<?php
require_once APPLICATION_PATH . "lib/func/func/exception/ExceptionHandler.php";
// TODO: only require MailUtils if emailing of exceptions has been activated
//require_once "src/services/MailUtils.php";
//require_once "conf.php";

class SqlException extends Exception implements ExceptionHandler{
	
	public function __construct($message, $code=NULL){
		parent::__construct($message . parent::getMessage(), $code);
    }
    
    public function __toString(){
        return "Message: " . htmlentities($this->getMessage());
    }
   /*
    public function getMessage(){
        return $this; // This will print the return from the above method __toString()
    }
    */
    public static function handleException($e){
    	
		echo $e->getMessage() . "<br/>" . $e->getTraceAsString();
    	
    	//$htmlTemplate = file_get_contents(HOST_URL . "/html/error.tpl");
		
		// render error message template
		//echo $htmlTemplate;
		// email the error to me
//		$emailBody = $e->getMessage() . "<br/>" . $e->getTraceAsString();
//		$mail = new MailUtils("mattmakins+wiisocial@gmail.com", "exception@wiisocial.mattmakins.co.uk", 
//			"[WiiSocial Error]: " . $e->getFile() . ": ". $e->getMessage(), $emailBody);
//		$mail->send();
    }
}
set_exception_handler(array("SqlException", "handleException"));
?>